% !Tex Program = xelatex
% \documentclass[a4paper]{article}
\documentclass[a4paper]{ctexart}
\usepackage{xltxtra}
% \setmainfont[Mapping=tex-text]{AR PL UMing CN:style=Light}
% \setmainfont[Mapping=tex-text]{AR PL UKai CN:style=Book}
% \setmainfont[Mapping=tex-text]{WenQuanYi Zen Hei:style=Regular}
% \setmainfont[Mapping=tex-text]{WenQuanYi Zen Hei Sharp:style=Regular}
% \setmainfont[Mapping=tex-text]{AR PL KaitiM GB:style=Regular} 
% \setmainfont[Mapping=tex-text]{AR PL SungtiL GB:style=Regular} 
% \setmainfont[Mapping=tex-text]{WenQuanYi Zen Hei Mono:style=Regular} 

\usepackage{listings}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{mathrsfs}

\usepackage{float} %图片悬浮

% ===================  定理类环境定义 ===================
\newtheorem{example}{例}              % 整体编号
\newtheorem{algorithm}{算法}
\newtheorem{theorem}{定理}[section]            % 按 section 编号
\newtheorem{definition}[theorem]{定义}
\newtheorem{axiom}[theorem]{公理}
\newtheorem{property}[theorem]{性质}
\newtheorem{proposition}[theorem]{命题}
\newtheorem{lemma}[theorem]{引理}
\newtheorem{corollary}[theorem]{推论}
\newtheorem{remark}[theorem]{注解}
\newtheorem{condition}[theorem]{条件}
\newtheorem{conclusion}[theorem]{结论}
\newtheorem{assumption}[theorem]{假设}
\newtheorem{formula}[theorem]{公式}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
  backgroundcolor=\color{backcolour},   
  commentstyle=\color{codegreen},
  keywordstyle=\color{magenta},
  numberstyle=\tiny\color{codegray},
  stringstyle=\color{codepurple},
  basicstyle=\ttfamily\footnotesize,
  breakatwhitespace=false,         
  breaklines=true,                 
  captionpos=b,                    
  keepspaces=true,                 
  numbers=left,                    
  numbersep=5pt,                  
  showspaces=false,                
  showstringspaces=false,
  showtabs=false,                  
  tabsize=2
}

\lstset{style=mystyle}

\title{有限元设计}
\author{倪金义}
\date{}
\begin{document}
\maketitle
\pagestyle{empty}

这是一个LaTeX模板.

空一行表示换段落.

\section{类设计}
\verb|class Point;|
\begin{lstlisting}[language=C++]
  class Point{
    protected:
    double value[DIM];

    public:
    double& operator[](const unsigned int d);
    const double& operator[](const unsigned int d) const;
  };
\end{lstlisting}

\verb|class Dofs;|
\begin{lstlisting}[language=C++]
  class Dofs{
    protected:
    Point<DIM> point;
    int globalIndex;//全局编号

    public:
    Dofs(const Point<DIM>& _point, int _global_index = 0):point{_point},globalIndex{_global_index}{};
    
    const Point<DIM>& getPoint() const;
    void setPoint(const Point<DIM>& _point);
    void setGlobalIndex(const int i){globalIndex=i;};
    int& getGlobalIndex(){return  globalIndex;};

    double& operator[](const unsigned int d){
      return point[d];
    };
  };
\end{lstlisting}

\verb|class Domain;|
\begin{lstlisting}[language=C++]
  class Domain{
    protected:
    std::vector<Point<DIM>> vertexList;/*< 定义域的边界顶点*/

    public:
  };
\end{lstlisting}

\verb|class Rectangle2D : public Domain<2>;|

\verb|class Grid;|
\begin{lstlisting}[language=C++]
  class Grid{
    protected:
    int num_of_vertices; /*< 顶点的数目*/
    vector<Point<DIM>> vertices;/*< 存储顶点的vector*/

    public:
  };
\end{lstlisting}

\verb|class Mesh;|
\begin{lstlisting}[language=C++]
  class Mesh{
    protected:
    vector<Grid<DIM>> gridList;/*< 存放所有的Grid*/
    vector<vector<Dofs<DIM>>> dofsOnGrid;/*< 存放grid上的所有自由度 */
    vector<Dofs<DIM>> boundaryDofs;/*< 存放所有边界上的自由度*/
    vector<int> seg;/*< 存放各维度分段数*/

    public:
    virtual int getTotalNumDofs() = 0;
    virtual int getNumGrid() = 0;
    virtual vector<Grid<DIM>>& getGridVector() = 0;
    virtual Grid<DIM> &getGrid(int _index) = 0;
    virtual vector<Dofs<DIM>>& getBoundaryDofs(int component = 0) = 0;
    virtual void distributeDofs() = 0;//洒自由度
    virtual vector<vector<Dofs<DIM>>>& getDofsOnGrid() = 0;
    virtual vector<int>& getSegment() = 0;
  };
\end{lstlisting}

\verb|class Q1Mesh : public Mesh<2>;|
\begin{lstlisting}[language=C++]
  class Q1Mesh{
    protected:

    public:
    Q1Mesh(Domain<2> domain, vector<int> _seg);
  };
\end{lstlisting}

\verb|class GaussianPoint;|
\begin{lstlisting}[language=C++]
  class GaussianPoint{
    protected:
    int _Algebraic_precision;
    vector<Point<DIM>> _GaussPoint;
    vector<double> _Weight;
    int _GaussianPointNum;
    
    public:
  };
\end{lstlisting}

\verb|class Quadrilateral_Element_GaussianInfo:public GaussianPoint<2>;|

\verb|class TemplateElement;|
\begin{lstlisting}[language=C++]
  class TemplateElement{
    protected:
    
    public:
    virtual void reinit(Grid<DIM>& _grid) = 0;
    virtual void setMesh(Mesh<DIM>& mesh) = 0;
  };
\end{lstlisting}

\verb|class Quadrilateral_1_Element:public TemplateElement<2>;|
\begin{lstlisting}[language=C++]
  class Quadrilateral_1_Element{
    protected:
    std::vector<Dofs<2> > _dofslist;/*< 存储绑定的Grid中自由度信息*/
    Quadrilateral_Element_GaussianInfo _GaussInfo;/*<Gauss积分所需：积分点和积分权重*/
    Q1Mesh _mesh;
    
    public:
  };
\end{lstlisting}

\verb|class FEMSpace;|
\begin{lstlisting}[language=C++]
  class FEMSpace{
    protected:
    
    public:
    virtual void setup_system() = 0;
    virtual void assemble_system() = 0;
    virtual void dealWithBoundaryCondition() = 0;
    virtual void solve() = 0;
  };
\end{lstlisting}

\verb|class Possion_2D : public FEMSpace<2>;|
\begin{lstlisting}[language=C++]
  class Possion_2D{
    protected:
    SpMat system_matrix;
    RHS system_rhs;
    Solution solution;
    Mesh<2>* _mesh;
    TemplateElement<2>* _element;
    Equation<2>* _eqation;
    
    public:
    Possion_2D(Mesh<2>*,TemplateElement<2>*,Equation<2>*);
  };
\end{lstlisting}

\verb|class Equation;|
\begin{lstlisting}[language=C++]
  class Equation{
    protected:
    
    public:
    typedef std::function<double(double*)> FunctionName;
    typedef std::function<double(double*)> FunctionNameBC;

    virtual void SetRightHandsTermFunction(FunctionName) = 0;
    virtual void SetBoundaryConditionFunction(FunctionNameBC) = 0;
    virtual void SetInitialConditionFunction(FunctionName) = 0;
    
    virtual FunctionName RightHandsTermFunction() = 0;
    virtual FunctionNameBC BoundaryConditionFunction() = 0;
    virtual FunctionName InitialConditionFunction() = 0;
  };
\end{lstlisting}

\verb|class PossionEquation:public Equation<DIM>;|

用\$A\$来表示数学字母$A$.

以下是简单的层次结构：
\begin{itemize}
\item
\begin{verbatim}
\begin{verbatim}表示逐字的,一字不差的,此环境可原样输出其中的文本,忽视LaTeX命令.

对简短的抄录,我们可使用\verb|文字|和\verb*|文字|.
\end{verbatim}
\item
\end{itemize}

下面讲讲$emacs$的常用操作
\begin{itemize}
\item 到文件开头\verb|M-<|;到文件末尾\verb|M->|.
\item 停止当前命令\verb|C-g|.
\item 查找替换\verb|M-%|,输入查找的词,回车,输入替换的词,回车,此处建议到文件开头进行查找替换,输入！替换全部.
\item {\bf 全选}区域\verb|C-x h|
\end{itemize}

借助\verb|Auctex|可以提高效率，如\verb|C-c C-e|可以快速插入环境

在\verb|equation|环境中插入空格用\verb|~|

\subsection{这是一个子标题}

我们用\verb|{\bf }|来{\bf 加粗}文字

\begin{enumerate}
\item \verb|enumerate|也拥有像\verb|itemize|一样的列表环境功能,但其拥有中文编号 
\item 这是第二个列表环境.
\end{enumerate}

下面我们来插入一张图片
\begin{figure}[H]
  \centering
  \includegraphics[width=0.95\textwidth]{picture/isoparametric_mapping.png} %自适应大小
  \caption{isoparametric mapping}
\end{figure}

下面我们来输入一个矩阵
\begin{equation}
  \left[
    \begin{array}{ccc}
      1 & 2\\
      3 & 2
    \end{array}\right]
\end{equation}

以下是$C++$环境的设计:

\begin{lstlisting}[language=C++]
  #ifndef __ENVIRONMENT__
  #define __ENVIRONMENT__

  #include <iostream>

  class ArrayList
  {};
  #else
  /// DO NOTHING.
  #endif
\end{lstlisting}

\bibliographystyle{plain}

\bibliography{aom.bib}

\end{document}
